<?php

//$phoneinfo =  getPhoneNumInfo('18591771963') ;
//echo  '18591771963: '."phoneinfo :".print_r($phoneinfo).'\n\t<br>';


$createtime = date('Y-m-d h:i:sa', time());
$table='uni_sys_smshis';
$data =  
array ( 
'mobile' =>'18591771963' ,  
'create_time' =>$createtime  ,
'update_time' =>$createtime  ,
'sms_key' => '6688',
'memo' => '商城充值发短信',
'flag' => '0'
 
       
);

echo   do_insert($data, $table) ;


function do_query($str) {
     require (dirname ( __FILE__ ) . '/config.php');
	//   	$connection = mysqli_connect ( $db_host, $db_user, $db_pass, $db_name ) or die ( "Unable to connect!" );
	 //$connection = mysqli_connect ( 'localhost:3308', 'root', 'jinga', 'myflow' ) or die ( "Unable to connect!" );
     //$connection = mysqli_connect ( explode(":",$db_host)[1], $db_user, $db_pass, $db_name,explode(":",$db_host)[2] )or die ( "Unable to connect!" );
     //$connection = mysqli_connect ( 'localhost', $db_user, $db_pass, $db_name,'3308' )or die ( "Unable to connect!" );
     $connection = mysqli_connect ( $db_host, $db_user, $db_pass, $db_name  )or die ( "Unable to connect!" );
 	mysqli_query($connection,'set names utf8');
	$result = mysqli_query ( $connection, $str ) or die ( "Error in insert . " . mysql_error () );
	
	return $result;
}

 function do_insert (&$data, $table )
  {    require (dirname ( __FILE__ ) . '/config.php');
  	 
  	$connection = mysqli_connect ( $db_host, $db_user, $db_pass, $db_name  )or die ( "Unable to connect!" );
  	mysqli_query($connection,'set names utf8');
  	
    $cols = implode(',', array_keys($data));
    foreach (array_values($data) as $value)
    {
      isset($vals) ? $vals .= ',' : $vals = '';
      $vals .= '\''.mysqli_real_escape_string($connection,$value).'\'';
    }
 //   $connection->real_query('INSERT INTO '.$table.' ('.$cols.') VALUES ('.$vals.')')   ;
  $result =    mysqli_query( $connection , 'INSERT INTO '.$table.' ('.$cols.') VALUES ('.$vals.')') or die ( "Error in insert . " . mysql_error () );
   return  $result ;
  }

function getPhoneNumInfo($pureNum) {
	$phoneNumHead = substr ( $pureNum, 0, 7 );
	$rec = do_query ( "SELECT province ,   corp  FROM  uni_mobile_belong a  WHERE    mobile =  \"" . $phoneNumHead . "\"" );
	if ($rec == false)
		$ret = array (
				'corp' => '00',
				'province_code' =>'00'
		);
	else {
		if ($rec->num_rows <= 0) {
			$ret = array (
					'corp' => '00',
					'province_code' =>'00'
			);
		} else {

			$row = $rec->fetch_assoc ();
			$ret = array (
					'corp' => $row['corp'],
					'province_code' => $row ['province']
			);

		}
	}
	return $ret;

}